package org.hxyjs.service.impl;


import org.hxyjs.dao.CarouselmapDao;
import org.hxyjs.dto.DTO;
import org.hxyjs.dto.MessageEnum;
import org.hxyjs.entity.Carouselmap;
import org.hxyjs.entity.Carouselmap;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.CarouselmapService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service("CarouselmapService")
public class CarouselmapServiceImpl implements CarouselmapService {
    @Resource
    CarouselmapDao carouselmapDao;
    @Override
    public DTO<Carouselmap> getAllCarouselmaps()  throws Exception{
        List<Carouselmap> carouselmaps = carouselmapDao.getAllCarouselmaps();
        MessageEnum messageEnum  = Optional.ofNullable(carouselmaps).isPresent()?MessageEnum.GETCAROUSELMAPSUCCESS: MessageEnum.GETCAROUSELMAPFAIL;
        return new DTO<Carouselmap>(messageEnum.getCode(),messageEnum.getMessage(),carouselmaps);
    }

    @Override
    public DTO<Carouselmap> deleteCarouselmapByCmno(String cmno)  throws Exception{
        Integer result = carouselmapDao.deleteCarouselmapByCmno(cmno);
        MessageEnum messageEnum  =result> 0?MessageEnum.DELETECAROUSELMAPSUCCESS:MessageEnum.DELETECAROUSELMAPFAIL;
        return new DTO<Carouselmap>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Carouselmap> updateCarouselmapByCmno(Carouselmap carouselmap)  throws Exception{
        Integer result = carouselmapDao.updateCarouselmapByCmno(carouselmap);
        MessageEnum messageEnum  =result> 0?MessageEnum.UPDATECAROUSELMAPSUCCESS:MessageEnum.UPDATECAROUSELMAPFAIL;
        return new DTO<Carouselmap>(messageEnum.getCode(),messageEnum.getMessage());
    }

    @Override
    public DTO<Carouselmap> addCarouselmap(Carouselmap carouselmap) throws Exception {
        Integer result = carouselmapDao.addCarouselmap(carouselmap);
        MessageEnum messageEnum  = result> 0?MessageEnum.ADDCAROUSELMAPSUCCESS:MessageEnum.ADDCAROUSELMAPFAIL;
        return new DTO<Carouselmap>(messageEnum.getCode(),messageEnum.getMessage());
    }
    @Override
    public DTO<Carouselmap> getCarouselmapByPage(PageInfo pageInfo ) throws Exception {
        List<Carouselmap> carouselmaps = carouselmapDao.getCarouselmapByPage(pageInfo);
        MessageEnum messageEnum  = Optional.ofNullable(carouselmaps).isPresent()?MessageEnum.GETCAROUSELMAPSUCCESS: MessageEnum.GETCAROUSELMAPFAIL;
        return new DTO<Carouselmap>(messageEnum.getCode(),messageEnum.getMessage(),carouselmaps,pageInfo);
    }
}
